package com.xiaodu.mybatis.mapper;

import com.xiaodu.mybatis.entity.UserEntity;
import com.xiaodu.mybatis.provider.UserProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author: dutianjie
 * @date: 2021/4/16
 * @version: v1.0.0
 * @description: 描述
 **/
@Mapper
@Repository
public interface UserMapper {


    UserEntity getOne(String id);

    @Select("select * from t_user where u_id = #{id}")
    @Results(id = "userResultMap2", value = {
            @Result(column = "u_name", property = "uName"),
            @Result(column = "u_id", property = "uId"),
            @Result(column = "money", property = "money"),
            @Result(column = "create_time", property = "createTime")
    })
    UserEntity selectOne(String id);

    @Select("select * from t_user where u_id = #{id}")
    @ResultMap("userResultMap")
//    @ResultMap("userResultMap2")
    UserEntity selectById(String id);
//
    @Select("<script>" +
            "  select * from t_user \n" +
            "        <where>\n" +
            "            u_id in\n" +
            "            <foreach collection=\"list\" item=\"id\" open=\"(\" close=\")\" separator=\",\">\n" +
            "                #{id}\n" +
            "            </foreach>\n" +
            "        </where>\n"+
                   "</script>")
    List<UserEntity> listUser(List<String> ids);


    @Insert("insert into t_user(u_id, u_name, password, money, create_time) values(#{uId}, #{uName},#{password}, #{money}, #{createTime})")
    int insertUser(UserEntity userEntity);


    @DeleteProvider(value = UserProvider.class, method = "delUser")
    int deleteUser(String id);

    @Update("update t_user set password = #{password}, money = #{money}, create_time = #{createTime} where u_id = #{uId}")
    int updateUser(UserEntity userEntity);


    @Select("select * from t_user")
    List<UserEntity> selectAll(RowBounds rowBounds);


    @Select("select * from t_user")
    List<UserEntity> selectUserAll();
}
